package com.zgt.util;

import java.util.List;

public class Page {
	
	private List pageResult;
	private int allRow;
	private int totalPage;
	private int currentPage;
	private int pageSize = 10;
	private int prevPage;
	private int nextPage;
	private int offset;
	
	private boolean isFirstPage;
	private boolean isLastPage;
	private boolean hasPreviousPage;
	private boolean hasNextPage;
	
	public String getPageInfo(){
		StringBuffer info= new StringBuffer(); 
			info.append("<a href='javascript:page(1)' title='First Page'>&laquo; 首页</a>");
			info.append("<a href='javascript:page(" + getPrevPage() + ")' title='Previous Page'>&laquo; 上一页</a>");
			
			int start = currentPage-2 >=1 ? currentPage - 2:1;
			start = totalPage > 5 ? totalPage-start <4 ? totalPage-4 : start :start;
			int end = totalPage > 5 ? (currentPage+2<=totalPage?currentPage+2:currentPage)<5? 5 : (currentPage+2<=totalPage?currentPage+2:currentPage) : totalPage;
			end = totalPage-currentPage ==1 ?totalPage :end;
			for (int i= start ; i<=end ; i++){
				info.append("<a href='javascript:page("+i+")' class='number" + (i==currentPage? " current":"") + "' title='" + i + "'>" + i + "</a>");
			}	
			
			info.append("<a href='javascript:page(" + getNextPage() + ")' title='Next Page'>下一页 &raquo;</a>");
			info.append("<a href='javascript:page(" + getTotalPage() + ")' title='Last Page'>尾页 &raquo;</a>");
		
		return info.toString();
	}
	
	public List getPageResult() {
		return pageResult;
	}
	
	public void setPageResult(List pageResult) {
		this.pageResult = pageResult;
	}

	public int getAllRow() {
		return allRow;
	}

	public void setAllRow(int allRow) {
		this.allRow = allRow;
		totalPage = allRow % pageSize == 0 ? allRow/pageSize : allRow/pageSize+1;
		currentPage = (currentPage == 0 ? 1 : currentPage);
		offset = pageSize*(currentPage-1);
		prevPage = (currentPage-1 <= 0 ? 1 : currentPage-1 );
		nextPage = (currentPage+1 >= totalPage ? totalPage : currentPage+1) ;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPrevPage() {
		return prevPage;
	}

	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public boolean isFirstPage() {
		return isFirstPage;
	}

	public void setFirstPage(boolean isFirstPage) {
		this.isFirstPage = isFirstPage;
	}

	public boolean isLastPage() {
		return isLastPage;
	}

	public void setLastPage(boolean isLastPage) {
		this.isLastPage = isLastPage;
	}

	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}
	
}
